<?php

class Application_Model_Blog extends Application_Model_Abstract {
	protected $_id;
	protected $_userId;
	protected $_title;
	protected $_posting;
	protected $_created;

	/**
	 * Array adapter, zur Vergleich, für DB-Tests
	 * @return array
	 */
	public function toArray() {
		return array('id' => $this->getId(), 'userId' => $this->getUserId(), 'title' => $this->getTitle(), 'posting' => $this->getPosting(),
			'created' => $this->getCreated(),);
	}

	/**
	 * @param int $id   primary key numerisch oder null
	 * @return Application_Model_Blog
	 */
	public function setId($id) {
		if ($id != "" || $id = null) {
			$this->_id = (int) $id;
		} else {
			$this->_id = null;
		}
		return $this;
	}

	/**
	 * @return int
	 */
	public function getId() {
		return $this->_id;
	}

	/**
	 * @param int $userId
	 * @return Application_Model_Blog
	 */
	public function setUserId($userId) {
		$this->_userId = (int) $userId;
		return $this;
	}

	/**
	 * @return int
	 */
	public function getUserId() {
		return $this->_userId;
	}

	/** Zugriff auf user-DB
	 * @return Application_Model_User
	 */
	public function getUser() {
		$userMapper = new Application_Model_UserMapper();
		$user = $userMapper->find($this->_userId);
		return $user;
	}

	/**
	 * @param string $text
	 * @return Application_Model_Blog
	 */
	public function setPosting($text) {
		$this->_posting = (string) $text;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getPosting() {
		return $this->_posting;
	}

	/**
	 * @param string $title
	 * @return Application_Model_Blog
	 */
	public function setTitle($title) {
		$this->_title = (string) $title;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getTitle() {
		return $this->_title;
	}

	/**
	 * @param string $ts
	 * @return Application_Model_Blog
	 */
	public function setCreated($ts) {
		$this->_created = new DateTime($ts);
		return $this;
	}

	/**
	 * @return DateTime
	 */
	public function getCreated() {
		return $this->_created;
	}

}